package com.sqly.doc.menu.fjh;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ihidea.multilinechooselib.MultiLineChooseLayout;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.menu.qianyue.qianyue_add;
import com.sqly.doc.pojo.FjhSf;
import com.sqly.doc.pojo.JuMin;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.user.choose_user;
import com.sqly.doc.util.BinderPojo;
import com.sqly.doc.util.BinderUtil;
import com.sqly.doc.util.CreateBitmap;
import com.sqly.doc.util.DateConvert;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.SweetAlertDialogUtil;
import com.sqly.doc.util.Url;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.util.WriteActivity;
import com.sqly.doc.view.CustomDatePicker;
import com.sqly.doc.view.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import cz.msebera.android.httpclient.Header;

//import cn.pedant.SweetAlert.SweetAlertDialog;


/**
 * Created by Administrator on 2017/11/22 0022.
 */

public class fjhsf extends MyBaseActivity {
    FjhSf obj;
    private CustomDatePicker customDatePicker;
    Context con = fjhsf.this;
    //标题
    TextView title, uname;
    LinearLayout back;

    @BinderPojo(value = R.id.SFJLH, name = "SFJLH", pojoProperty = true)
    private TextView SFJLH;

    @BinderPojo(value = R.id.XINGMING, name = "XINGMING", pojoProperty = true, require = true, promptMsg = "请选择患者信息")
    private TextView XINGMING;

    @BinderPojo(value = R.id.SFRQ, name = "SFRQ", pojoProperty = true, require = true, promptMsg = "请选择随访日期")
    private TextView SFRQ;

    @BinderPojo(value = R.id.XCSFRQ, name = "XCSFRQ", pojoProperty = true, require = true, promptMsg = "请选择下次随访日期")
    private TextView XCSFRQ;

    @BinderPojo(value = R.id.ZLYX, name = "ZLYX", pojoProperty = true, require = true, regex = "^[1-9]\\d*$", promptMsg = "请输入正确治疗月序")
    EditText ZLYX;

    @BinderPojo(value = R.id.ZZQT, name = "ZZQT", pojoProperty = true)
    EditText ZZQT;

    @BinderPojo(value = R.id.SHXY, name = "SHXY", pojoProperty = true)
    EditText SHXY;//吸烟

    @BinderPojo(value = R.id.SHXYZD, name = "SHXYZD", pojoProperty = true)
    EditText SHXYZD;//吸烟指导

    @BinderPojo(value = R.id.SHYJ, name = "SHYJ", pojoProperty = true)
    EditText SHYJ;//饮酒

    @BinderPojo(value = R.id.SHYJZD, name = "SHYJZD", pojoProperty = true)
    EditText SHYJZD;//饮酒指导

    @BinderPojo(value = R.id.HLFA, name = "HLFA", pojoProperty = true)
    EditText HLFA;//化疗方案

    @BinderPojo(value = R.id.LFYCS, name = "LFYCS", pojoProperty = true)
    EditText LFYCS;//漏服药(次)

    @BinderPojo(value = R.id.YLBLFYY, name = "YLBLFYY", pojoProperty = true)
    EditText YLBLFYY;

    @BinderPojo(value = R.id.BFZHBZY, name = "BFZHBZY", pojoProperty = true)
    EditText BFZHBZY;//并发症或合并症 选择有选项需要填写

    @BinderPojo(value = R.id.ZZYY, name = "ZZYY", pojoProperty = true)
    EditText ZZYY;//转诊原因

    @BinderPojo(value = R.id.ZZJGJKB, name = "ZZJGJKB", pojoProperty = true)
    EditText ZZJGJKB;//转诊机构及科室

    @BinderPojo(value = R.id.LZNSFJG, name = "LZNSFJG", pojoProperty = true)
    EditText LZNSFJG;//2周内随访随访结果

    @BinderPojo(value = R.id.CLYJ, name = "CLYJ", pojoProperty = true)
    EditText CLYJ;//处理意见;

    @BinderPojo(value = R.id.CXTZZLSJ, name = "CXTZZLSJ", pojoProperty = true)
    TextView CXTZZLSJ;//出现停止治疗时间

    @BinderPojo(value = R.id.QCGLYFSCS, name = "QCGLYFSCS", pojoProperty = true)
    EditText QCGLYFSCS;//全程管理情况-应访视患者次数（次)

    @BinderPojo(value = R.id.QCGLSJFSCS, name = "QCGLSJFSCS", pojoProperty = true)
    EditText QCGLSJFSCS;//全程管理情况-实际访视患者(次)

    @BinderPojo(value = R.id.QCGLYFYCS, name = "QCGLYFYCS", pojoProperty = true)
    EditText QCGLYFYCS;//全程管理情况-应服药(次)

    @BinderPojo(value = R.id.QCGLSJFYCS, name = "QCGLSJFYCS", pojoProperty = true)
    EditText QCGLSJFYCS;//全程管理情况-实际服药(次)

    RadioGroup sffs, ddry, yf, ywblfy, bfz, TZZLYY,LZNSF;
    MultiLineChooseLayout zzjtz,ypjx;
    private List<String> zzjtzdata = new ArrayList<>();
    private List<String> yplxdata = new ArrayList<>();

    ImageView sfysqm, brqm, xcqm;
    String sfysqmpic = "", brqmpic = "",xcqmpic ="";
    boolean isadd = false;//是否是新添加
    String url = "", JKDAH = "";
    JuMin j;

    ImageView xcpaizhao;
    TextView pz_record_id,jmqm_record_id, ysqm_record_id;
    boolean pzChange = false;

    @Override
    protected void initUI() {
        setContentView(R.layout.fjhsf);
        BinderUtil.exeFindById(fjhsf.this);
        if (NetWorkUtils.isNetworkConnected(con)) {
            if (getIntent().getStringExtra("type").equals("edit")) {
                obj = (FjhSf) getIntent().getExtras().getSerializable("b");
                init(obj);
                if(!StringUtils.isEmpty(obj.getImg())){
                    //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg(),brqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg()),brqm);
                }
                if(!StringUtils.isEmpty(obj.getImg1())){
                    //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg1(),sfysqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg1()),sfysqm);
                }
                if(!StringUtils.isEmpty(obj.getImg2())){
                    //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg2(),xcqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg2()),xcqm);
                }
            }else {
                obj = new FjhSf();
                init(obj);
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {

        } else {
            if (requestCode == 1) {
                j = (JuMin) data.getExtras().getSerializable("j");
                getObject();
            }else if (requestCode == 8) {
                String record_id = (String) data.getExtras().getString("record_id");
                ysqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                sfysqm.setImageBitmap(bb);
                sfysqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if (requestCode == 9) {
                String record_id = (String) data.getExtras().getString("record_id");
                jmqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                brqm.setImageBitmap(bb);
                brqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if(requestCode == 119){
                String img_record_id = (String) data.getExtras().getString("img_record_id");
                pz_record_id.setText(img_record_id);
                pzChange = true;
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                xcqm.setImageBitmap(bb);
            }
        }
    }

    public void getObject() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        ps.add("CARDNUM", j.getCARDNUM());
        UserClient.get(HttpUrl.GetFjhsfGrjbxx, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {
                    JSONObject j = JSON.parseObject(ret.getRd());
                    obj = new FjhSf();
                    init(obj);
                    obj.setJKDAH(j.getString("JKDAH"));
                    obj.setXINGMING(j.getString("XINGMING"));
                    obj.setCARDNUM(j.getString("CARDNUM"));
                    JKDAH = j.getString("JKDAH");
                    XINGMING.setText(j.getString("XINGMING"));

                    isadd = true;
                } else {
                    SweetAlertDialogUtil.ErrorDialogNoFinish(con, "错误提示", ret.getInfo(), "确定");
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                isadd = true;
                obj = new FjhSf();
                init(obj);
            }
        });
    }

    public void init(final FjhSf obj) {
        //运行时生成activity中所有控件的findViewById方法
        //BinderUtil.exeFindById(fjhdycrhsf.this);
        BinderUtil.initData(fjhsf.this, obj);
        //医生签名
        sfysqm = (ImageView) findViewById(R.id.sfysqm);
        sfysqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhsf")
                        .putExtra("imageType", "img1")
                        .putExtra("class", "fjhsf.class"), 8);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getSfysqm())) {
            sfysqmpic = obj.getSfysqm();
            sfysqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + sfysqmpic + ".jpg"));
        }
        //本人签名
        brqm = (ImageView) findViewById(R.id.brqm);
        brqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhsf")
                        .putExtra("imageType", "img")
                        .putExtra("class", "fjhsf.class"), 9);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getBrqm())) {
            brqmpic = obj.getBrqm();
            brqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + brqmpic + ".jpg"));
        }
        xcqm = (ImageView) findViewById(R.id.xcqm);
        if (obj != null && !StringUtils.isEmpty(obj.getXcqm())) {
            xcqmpic = obj.getXcqm();
            xcqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + xcqmpic + ".jpg"));
        }
        xcqm.setOnClickListener(new CustomerListener());

        if (obj != null && !StringUtils.isEmpty(obj.getXINGMING())) {
            XINGMING.setText(obj.getXINGMING());
        } else {
            XINGMING.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(con, choose_user.class).putExtra("cname", "fjhsf.class"), 1);
                }
            });
        }
        //现场拍照
        xcpaizhao = (ImageView) findViewById(R.id.xcpaizhao);
        xcpaizhao.setOnClickListener(new CustomerListener());
        //现场拍照照片id
        pz_record_id = (TextView) findViewById(R.id.pz_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg2())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg2().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                pz_record_id.setText(img2Arr[1]);
            }
        }
        jmqm_record_id= (TextView) findViewById(R.id.jmqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg())) {
            String[] img2Arr =obj.getImg().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                jmqm_record_id.setText(img2Arr[1]);
            }
        }
        ysqm_record_id= (TextView) findViewById(R.id.ysqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg1())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg1().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                ysqm_record_id.setText(img2Arr[1]);
            }
        }

        back = (LinearLayout) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pzChange){
                   SweetAlertDialogUtil.WarningDialogHaveCancelAndConfirm(con,"你确认不保存数据更新吗？","现场拍照已经采集，请注意点击“保存”","确定", "返回");
                }else {
                    finish();
                }
            }
        });
        //标题
        title = (TextView) findViewById(R.id.title);
        uname = (TextView) findViewById(R.id.uname);
        title.setText("肺结核患者随访服务记录");
        uname.setText("保存");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean validate = BinderUtil.copyDataToView(fjhsf.this, obj);
                if (!validate) {

                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "ysqm", "0").toString()) && ysqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "随访医生签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "jmqm", "0").toString()) && jmqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "家属或本人签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "xcpz", "0").toString()) && pz_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "现场拍照不能为空");
                } else if (NetWorkUtils.isNetworkConnected(con)) {  ///网络连接
                    RequestParams ps = BinderUtil.generateRequestParamsByView(fjhsf.this);
                    if (isadd) {
                        ps.add("entity.JKDAH", JKDAH);
                        url = HttpUrl.SaveFjhsf;
                    } else {
                        ps.add("entity.SFJLH", obj.getSFJLH());
                        ps.add("entity.JKDAH", obj.getJKDAH());
                        url = HttpUrl.EditFjhsf;
                    }

                    ps.add("entity.DDRY", obj.getDDRY());
                    ps.add("entity.SFFS", obj.getSFFS());
                    ps.add("entity.HLYF", obj.getHLYF());
                    //zzjtz, yplx
                    ArrayList<Integer> zdlist = zzjtz.getAllItemSelectedIndex();
                    String bjzds = "";
                    for (int i = 0; i < zdlist.size(); i++) {
                        if (i == 0)
                            bjzds =  (Integer.parseInt(zdlist.get(i)+"")+1)+ "";
                        else
                            bjzds = bjzds + "," + (Integer.parseInt(zdlist.get(i)+"")+1);
                    }
                    ps.add("entity.ZHENGZHUANG", bjzds);
                    //zzjtz, yplx
                    ArrayList<Integer> jllist = ypjx.getAllItemSelectedIndex();
                    String jxzds = "";
                    for (int i = 0; i < jllist.size(); i++) {
                        if (i == 0)
                            jxzds = (Integer.parseInt(jllist.get(i)+"")+1) + "";
                        else
                            jxzds = jxzds + "," + (Integer.parseInt(jllist.get(i)+"")+1);
                    }
                    ps.add("entity.YPJX", jxzds);
                    ps.add("entity.YLBLFY", obj.getYLBLFY());
                    ps.add("entity.BFZHBZ", obj.getBFZHBZ());
                    ps.add("entity.LZNSF", obj.getLZNSF());
                    ps.add("entity.TZZLYY", obj.getTZZLYY());

                    ps.add("entity.CARDNUM", obj.getCARDNUM());
                    ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
                    ps.add("type", "2");

                    ps.add("pz_record_id", pz_record_id.getText().toString());
                    ps.add("jmqm_record_id", jmqm_record_id.getText().toString());
                    ps.add("ysqm_record_id", jmqm_record_id.getText().toString());
                    ps.add("entity.UPDATETIME", obj.getUPDATETIME());
                    //fjhsf.super.ImageUploadOperate(sfysqmpic, brqmpic, ps);
                    UserClient.get(url, ps, new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                            String content = new String(response);
                            RetMsg ret = JSON.parseObject(content, RetMsg.class);
                            if (ret.getCode().equals("200")) {
                                MyToastUtil.ShowToast(con, "成功");
                            }else{
                                MyToastUtil.ShowToast(con, ret.getInfo());
                            }
                            finish();
                        }

                        @Override
                        public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                            MyToastUtil.ShowToast(con, "失败");
                        }
                    });
                } else {
                    MyToastUtil.ShowToast(con, "失败");
                }
            }
        });
        //随访日期
        //SFRQ = (TextView) findViewById(R.id.SFRQ);
        SFRQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        SFRQ.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getSFRQ())){
            SFRQ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        //下次随访日期
        //XCSFRQ = (TextView) findViewById(R.id.XCSFRQ);
        XCSFRQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        XCSFRQ.setText(time.split(" ")[0]);

                    }
                }, DateConvert.getCustomDatePickerStartRq(), DateConvert.getCustomDatePickerEndRq()); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(DateConvert.getCustomDatePickerNowRq());
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getXCSFRQ())){
            XCSFRQ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getXCSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        //治疗月序
        // ZLYX = (EditText) findViewById(R.id.ZLYX);
        if (obj != null && !StringUtils.isEmpty(obj.getZLYX())) {
            ZLYX.setText(obj.getZLYX());
        }
        //症状及体征-其他
        //ZZQT = (EditText) findViewById(R.id.ZZQT);
        if (obj != null && !StringUtils.isEmpty(obj.getZZQT())) {
            ZZQT.setText(obj.getZZQT());
        }
        //生活-吸烟
        //SHXY = (EditText) findViewById(R.id.SHXY);
        if (obj != null && !StringUtils.isEmpty(obj.getSHXY())) {
            SHXY.setText(obj.getSHXY());
        }
        //生活-吸烟-指导
        //SHXYZD = (EditText) findViewById(R.id.SHXYZD);
        if (obj != null && !StringUtils.isEmpty(obj.getSHXY())) {
            SHXYZD.setText(obj.getSHXYZD());
        }
        //生活-饮酒
        //SHYJ = (EditText) findViewById(R.id.SHYJ);
        if (obj != null && !StringUtils.isEmpty(obj.getSHYJ())) {
            SHYJ.setText(obj.getSHYJ());
        }
        //生活-饮酒-指导
        //SHYJZD = (EditText) findViewById(R.id.SHYJZD);
        if (obj != null && !StringUtils.isEmpty(obj.getSHYJZD())) {
            SHYJZD.setText(obj.getSHYJZD());
        }
        //化疗方案
        //HLFA = (EditText) findViewById(R.id.HLFA);
        if (obj != null && !StringUtils.isEmpty(obj.getHLFA())) {
            HLFA.setText(obj.getHLFA());
        }
        //药物不良反应-有-填写
        //YLBLFYY = (EditText) findViewById(R.id.YLBLFYY);
        if (obj != null && !StringUtils.isEmpty(obj.getYLBLFYY())) {
            YLBLFYY.setText(obj.getYLBLFYY());
        }
        //并发症或合并症 选择有选项需要填写
        //BFZHBZY = (EditText) findViewById(R.id.BFZHBZY);
        if (obj != null && !StringUtils.isEmpty(obj.getBFZHBZY())) {
            BFZHBZY.setText(obj.getBFZHBZY());
        }
        //转诊原因
        //ZZYY = (EditText) findViewById(R.id.ZZYY);
        if (obj != null && !StringUtils.isEmpty(obj.getZZYY())) {
            ZZYY.setText(obj.getZZYY());
        }
        //转诊机构及科室
        //ZZJGJKB = (EditText) findViewById(R.id.ZZJGJKB);
        if (obj != null && !StringUtils.isEmpty(obj.getZZJGJKB())) {
            ZZJGJKB.setText(obj.getZZJGJKB());
        }
        //2周内随访结果
        //LZNSFJG = (EditText) findViewById(R.id.LZNSFJG);
        if (obj != null && !StringUtils.isEmpty(obj.getLZNSFJG())) {
            LZNSFJG.setText(obj.getLZNSFJG());
        }
        //处理意见
        //CLYJ = (EditText) findViewById(R.id.CLYJ);
        if (obj != null && !StringUtils.isEmpty(obj.getCLYJ())) {
            CLYJ.setText(obj.getCLYJ());
        }
        //出现停止治疗时间
        //CXTZZLSJ = (TextView) findViewById(R.id.CXTZZLSJ);
        if (obj != null && !StringUtils.isEmpty(obj.getCXTZZLSJ())) {
            CXTZZLSJ.setText(obj.getCXTZZLSJ());
        }
        CXTZZLSJ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        CXTZZLSJ.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getCXTZZLSJ())){
            CXTZZLSJ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getCXTZZLSJ(), DateConvert.YMD), DateConvert.YMD)+"    ");
        }
        //应访视患者
        //QCGLYFSCS = (EditText) findViewById(R.id.QCGLYFSCS);
        if (obj != null && !StringUtils.isEmpty(obj.getQCGLYFSCS())) {
            QCGLYFSCS.setText(obj.getQCGLYFSCS());
        }
        //全程管理情况-实际访视患者(次)
        //QCGLSJFSCS = (EditText) findViewById(R.id.QCGLSJFSCS);
        if (obj != null && !StringUtils.isEmpty(obj.getQCGLSJFSCS())) {
            QCGLSJFSCS.setText(obj.getQCGLSJFSCS());
        }
        //全程管理情况-应服药(次)
        //QCGLYFYCS = (EditText) findViewById(R.id.QCGLYFYCS);
        if (obj != null && !StringUtils.isEmpty(obj.getQCGLYFYCS())) {
            QCGLYFYCS.setText(obj.getQCGLYFYCS());
        }
        //全程管理情况-实际服药(次)
        //QCGLSJFYCS = (EditText) findViewById(R.id.QCGLSJFYCS);
        if (obj != null && !StringUtils.isEmpty(obj.getQCGLSJFYCS())) {
            QCGLSJFYCS.setText(obj.getQCGLSJFYCS());
        }
        //漏服药次数
        LFYCS = (EditText) findViewById(R.id.LFYCS);
        if (obj != null && !StringUtils.isEmpty(obj.getLFYCS())) {
            LFYCS.setText(obj.getLFYCS());
        }


        //督导人员
        ddry = (RadioGroup) findViewById(R.id.jdryxz);
        if (obj != null && !StringUtils.isEmpty(obj.getDDRY())) {
            switch (Integer.parseInt(obj.getDDRY())) {
                case 1:
                    ddry.check(R.id.jdryxz1);
                    break;
                case 2:
                    ddry.check(R.id.jdryxz2);
                    break;
                case 3:
                    ddry.check(R.id.jdryxz3);
                    break;
                case 4:
                    ddry.check(R.id.jdryxz4);
                    break;
            }
        }
        ddry.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.jdryxz1) {
                    obj.setDDRY("1");
                } else if (checkedId == R.id.jdryxz2) {
                    obj.setDDRY("2");
                } else if (checkedId == R.id.jdryxz3) {
                    obj.setDDRY("3");
                } else {
                    obj.setDDRY("4");
                }
            }
        });
        //随访方式
        sffs = (RadioGroup) findViewById(R.id.sffs);
        if (obj != null && !StringUtils.isEmpty(obj.getSFFS())) {
            switch (Integer.parseInt(obj.getSFFS())) {
                case 1:
                    sffs.check(R.id.sffs1);
                    break;
                case 2:
                    sffs.check(R.id.sffs2);
                    break;
                case 3:
                    sffs.check(R.id.sffs3);
                    break;
            }
        }
        sffs.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.sffs1) {
                    obj.setSFFS("1");
                } else if (checkedId == R.id.sffs2) {
                    obj.setSFFS("2");
                } else {
                    obj.setSFFS("3");
                }
            }
        });
        //用药用法
        yf = (RadioGroup) findViewById(R.id.HLYF);
        if (obj != null && !StringUtils.isEmpty(obj.getHLYF())) {
            switch (Integer.parseInt(obj.getHLYF())) {
                case 1:
                    yf.check(R.id.yf1);
                    break;
                case 2:
                    yf.check(R.id.yf2);
                    break;

            }
        }
        yf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.yf1) {
                    obj.setHLYF("1");
                } else {
                    obj.setHLYF("2");
                }
            }
        });
        //药品剂型
        ypjx = (MultiLineChooseLayout) findViewById(R.id.YPJX);
        yplxdata.add("固定剂量复合制剂");
        yplxdata.add("散装药");
        yplxdata.add("板式组合药");
        yplxdata.add("注射剂");
        ypjx.setList(yplxdata);
        if (obj != null && !StringUtils.isEmpty(obj.getYPJX())) {
            if (obj.getYPJX().contains("1"))
                ypjx.setIndexItemSelected(0);
            if (obj.getYPJX().contains("2"))
                ypjx.setIndexItemSelected(1);
            if (obj.getYPJX().contains("3"))
                ypjx.setIndexItemSelected(2);
            if (obj.getYPJX().contains("4"))
                ypjx.setIndexItemSelected(3);
        }

        //药物不良反应
        ywblfy = (RadioGroup) findViewById(R.id.YLBLFY);
        if (obj != null && !StringUtils.isEmpty(obj.getYLBLFY())) {
            switch (Integer.parseInt(obj.getYLBLFY())) {
                case 1:
                    ywblfy.check(R.id.ywblfy1);
                    break;
                case 2:
                    ywblfy.check(R.id.ywblfy2);
                    break;

            }
        }
        ywblfy.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.ywblfy1) {
                    obj.setYLBLFY("1");
                } else {
                    obj.setYLBLFY("2");
                }
            }
        });
        //并发症或合并症
        bfz = (RadioGroup) findViewById(R.id.BFZHBZ);
        if (obj != null && !StringUtils.isEmpty(obj.getBFZHBZ())) {
            switch (Integer.parseInt(obj.getBFZHBZ())) {
                case 1:
                    bfz.check(R.id.bfz1);
                    break;
                case 2:
                    bfz.check(R.id.bfz2);
                    break;

            }
        }
        bfz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.bfz1) {
                    obj.setBFZHBZ("1");
                } else {
                    obj.setBFZHBZ("2");
                }
            }
        });
        //2周内随访
        LZNSF= (RadioGroup) findViewById(R.id.LZNSF);
        if (obj != null && !StringUtils.isEmpty(obj.getLZNSF())) {
            switch (Integer.parseInt(obj.getLZNSF())) {
                case 1:
                    LZNSF.check(R.id.LZNSF1);
                    break;
                case 2:
                    LZNSF.check(R.id.LZNSF2);
                    break;

            }
        }
        LZNSF.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.LZNSF1) {
                    obj.setLZNSF("1");
                } else {
                    obj.setLZNSF("2");
                }
            }
        });
        //停止治疗原因
        TZZLYY = (RadioGroup) findViewById(R.id.TZZLYY);
        if (obj != null && !StringUtils.isEmpty(obj.getTZZLYY())) {
            switch (Integer.parseInt(obj.getTZZLYY())) {
                case 1:
                    TZZLYY.check(R.id.tzzlyy1);
                    break;
                case 2:
                    TZZLYY.check(R.id.tzzlyy2);
                    break;
                case 3:
                    TZZLYY.check(R.id.tzzlyy3);
                    break;
                case 4:
                    TZZLYY.check(R.id.tzzlyy4);
                    break;

            }
        }
        TZZLYY.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.tzzlyy1) {
                    obj.setTZZLYY("1");
                } else if (checkedId == R.id.tzzlyy2) {
                    obj.setTZZLYY("2");
                } else if (checkedId == R.id.tzzlyy3) {
                    obj.setTZZLYY("3");
                } else {
                    obj.setTZZLYY("4");
                }
            }
        });


        zzjtz = (MultiLineChooseLayout) findViewById(R.id.fypg);
        zzjtzdata.add("没有症状");
        zzjtzdata.add("咳嗽咳痰");
        zzjtzdata.add("低热盗汗");
        zzjtzdata.add("咳血或血痰");
        zzjtzdata.add("胸痛消瘦");
        zzjtzdata.add("恶心纳差");
        zzjtzdata.add("关节疼痛");
        zzjtzdata.add("头痛失眠");
        zzjtzdata.add("视物模糊");
        zzjtzdata.add("皮肤瘙痒、皮疹");
        zzjtzdata.add("耳鸣、听力下降");
        zzjtz.setList(zzjtzdata);
        if (obj != null && !StringUtils.isEmpty(obj.getZHENGZHUANG())) {
            String[] zzList = obj.getZHENGZHUANG().split(",");

            if (Arrays.asList(zzList).contains("1"))
                zzjtz.setIndexItemSelected(0);
            if (Arrays.asList(zzList).contains("2"))
                zzjtz.setIndexItemSelected(1);
            if (Arrays.asList(zzList).contains("3"))
                zzjtz.setIndexItemSelected(2);
            if (Arrays.asList(zzList).contains("4"))
                zzjtz.setIndexItemSelected(3);
            if (Arrays.asList(zzList).contains("5"))
                zzjtz.setIndexItemSelected(4);
            if (Arrays.asList(zzList).contains("6"))
                zzjtz.setIndexItemSelected(5);
            if (Arrays.asList(zzList).contains("7"))
                zzjtz.setIndexItemSelected(6);
            if (Arrays.asList(zzList).contains("8"))
                zzjtz.setIndexItemSelected(7);
            if (Arrays.asList(zzList).contains("9"))
                zzjtz.setIndexItemSelected(8);
            if (Arrays.asList(zzList).contains("10"))
                zzjtz.setIndexItemSelected(9);
            if (Arrays.asList(zzList).contains("11"))
                zzjtz.setIndexItemSelected(10);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    class CustomerListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if(obj != null && StringUtils.isEmpty(obj.getJKDAH())) {
                SweetAlertDialogUtil.WarningDialog(con, "提示", "选择居民用户后才能现场拍照");
            }else {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhsf")
                        .putExtra("class", "fjhsf.class");
                startActivityForResult(intent, 119);
            }
        }
    }
}
